<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="csrf_token" id="token" content="{{ csrf_token() }}">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    @include('public.h5_head')
    <title>总榜</title>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/rem.js"></script>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/common.css"/>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/rank.css"/>
</head>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/app.js"></script>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/iscroll.js"></script>
<body onload="loaded()">
<div id="rank_box">
    <div class="rank_top">
        <div class="rank_week">
            <div class="separate">
                <p class="rank_one rank_tp">周榜</p>
                <p class="rank_two rank_tp on">总榜</p>
            </div>
            <p class="rank_line"><span class="line" style="position:absolute;top:0;right:0;"></span></p>
        </div>
        <div class="rank_area">
            <ul class="rank_ul">
                <li class="rank_li current">{{ $area_infos[2]->area_name }}</li>
                <li class="rank_li">{{ $area_infos[1]->area_name }}</li>
                <li class="rank_li">{{ $area_infos[0]->area_name }}</li>
            </ul>
            <p class="area_line"><span class="line_sp"></span></p>
        </div>
    </div>
    <div class="wrap">
        <div class="rank_main">
            <ol class="rank_ol">
                <!--区-->
                <li class="ol_li" style="display:block;">
                    <ul class="rank_number">
                        <?php $a=1 ; $b=1 ;$c=1?>
                        @foreach($area as $k => $v)

                        <li class="li_1 rank_con user_{{ $v->id }}">
                            <span class="rank_sp1">{{ $a }}</span>
                            <div class="rank_img">
                                @if($v->face == '0' )
                                    <img src="/img/head2x.png"/>
                                @else
                                    <img src="{{ $v->face }}"/>
                                @endif
                            </div>
                            <p class="rank_name">{{ $v->nickname }}</p>
                            <p class="rank_integral">￥<span class="number_rank">{{ $v->integral }}</span></p>
                            <dl class="rank_heart">
                                <dt class="heart_sum">
                                    @if(isset($user_heart_num[$v->id]))
                                        {{ $user_heart_num[$v->id] }}
                                    @else
                                        0
                                    @endif
                                </dt>
                                <dd class="heart">
                                    @if(isset($click_log[$v->id]))
                                        <img class="heart_img" title="{{ $v->id }}" src="/img/heart-y.png"/>
                                    @else
                                        <img class="heart_img" title="{{ $v->id }}" src="/img/heart-n.png"/>
                                    @endif
                                </dd>
                            </dl>
                        </li>
                    <?php $a++; ?>
                    @endforeach
                        <!--添加-->
                    </ul>
                </li>

                <!--市-->

                <li class="ol_li">
                    <ul class="rank_number">
                        @foreach($city as $k => $v)
                        <li class="li_2 rank_con user_{{ $v->id }}">
                            <span class="rank_sp1">{{ $b }}</span>
                            <div class="rank_img">
                                @if($v->face == '0' )
                                    <img src="/img/head2x.png"/>
                                @else
                                    <img src="{{ $v->face }}"/>
                                @endif
                            </div>
                            <p class="rank_name">{{ $v->nickname }}</p>
                            <p class="rank_integral">￥<span class="number_rank">{{ $v->integral }}</span></p>
                            <dl class="rank_heart">
                                <dt class="heart_sum">
                                    @if(isset($user_heart_num[$v->id]))
                                        {{ $user_heart_num[$v->id] }}
                                    @else
                                        0
                                    @endif
                                </dt>
                                <dd class="heart">
                                    @if(isset($click_log[$v->id]))
                                        <img class="heart_img" title="{{ $v->id }}" src="/img/heart-y.png"/>
                                    @else
                                        <img class="heart_img" title="{{ $v->id }}" src="/img/heart-n.png"/>
                                    @endif
                                </dd>
                            </dl>
                        </li>
                            <?php $b++; ?>
                    @endforeach
                        <!--添加-->
                    </ul>

                </li>

                <!--省-->
                <li class="ol_li">

                    <ul class="rank_number">
                        @foreach($infos as $k => $v)
                        <li class="li_3 rank_con user_{{ $v->id }}">
                            <span class="rank_sp1">{{$c}}</span>
                            <div class="rank_img">
                                @if($v->face == '0' )
                                    <img src="/img/head2x.png"/>
                                @else
                                    <img src="{{ $v->face }}"/>
                                @endif
                            </div>
                            <p class="rank_name">{{ $v->nickname }}</p>
                            <p class="rank_integral">￥<span class="number_rank">{{ $v->integral }}</span></p>
                            <dl class="rank_heart">
                                <dt class="heart_sum">
                                    @if(isset($user_heart_num[$v->id]))
                                        {{ $user_heart_num[$v->id] }}
                                    @else
                                        0
                                    @endif
                                </dt>
                                <dd class="heart">
                                    @if(isset($click_log[$v->id]))
                                        <img class="heart_img" title="{{ $v->id }}" src="/img/heart-y.png"/>
                                    @else
                                        <img class="heart_img" title="{{ $v->id }}" src="/img/heart-n.png"/>
                                    @endif
                                </dd>
                            </dl>
                        </li>
                            <?php $c++;?>
                    @endforeach
                        <!--添加-->
                    </ul>

                </li>
            </ol>
        </div>
    </div>
    <!--自己的-->
    <ul class="self_number">
        <li class="self_con">
            <span class="self_sp1">1</span>
            <div class="self_img">
                <img src="{{ Auth::user()->face }}"/>
            </div>
            <p class="self_name">{{ Auth::user()->nickname }}</p>
            <p class="self_integral">￥<span class="number_integral">{{ Auth::user()->integral }}</span></p>
            <dl class="self_heart">
                <dt class="self_sum"></dt>
                <dd class="self"><img class="heart_oneself" src="/img/heart-n.png"/></dd>
            </dl>
        </li>
    </ul>
</div>
</body>
<script>
    /*滚动*/
    var myScroll;
    function loaded () {
        setTimeout(function(){
            myScroll = new IScroll('.wrap', {
                mouseWheel: true,
                click: true,
                checkDOMChanges:true
            });
        },100);
    }
    document.addEventListener('touchmove', function (e) {e.preventDefault();},false);
    /*跳转周榜*/
    $(".rank_one").click(function(){
        window.location.href="/user/lastWeekRanking";
    })
    /*省市区滑动*/
    $(".rank_ul").children(".rank_li").click(function(){
        setTimeout(function () {
            myScroll.refresh();
        }, 10);
        var n=$(this).index();
        $(this).addClass("current").siblings().removeClass("current");
        $(".rank_ol .ol_li").css("display","none")
        $(".rank_ol .ol_li:eq("+n+")").css("display","block")
        $('.line_sp').stop().animate({'marginLeft': n*5.33+"rem"}, 300,function(){
        })
        var self_id =  '{{ Auth::user()->id}}';
        $(".li_"+(n+1)+"").each(function(){
            var old=$(this).attr('class');
            var arr=old.split("_");
            if(arr[3]==self_id){
                $(this).css("background","#f1f1f1");
                $('.self_sp1').text($(this).children('.rank_sp1').text());
                $('.self_sum').text($(this).children('.rank_heart').children('.heart_sum').text());
                var Img=$(this).children('.rank_heart').children('.heart').children('.heart_img').attr("src");
                $('.heart_oneself').attr("src",Img);
            }
        })
    })

    /*初始化获取自己信息*/
    var self_id =  '{{ Auth::user()->id}}';
    $(".li_1").each(function(){
        var old=$(this).attr('class');
        console.log(old)
        var arr=old.split("_");
        console.log(arr)
        if(arr[3]==self_id){
            $(this).css("background","#f1f1f1");
            $('.self_sp1').text($(this).children('.rank_sp1').text());
            $('.self_sum').text($(this).children('.rank_heart').children('.heart_sum').text());
            var Img=$(this).children('.rank_heart').children('.heart').children('.heart_img').attr("src");
            $('.heart_oneself').attr("src",Img);
        }
    })
    /*点赞换图数量加减*/
    $('.rank_heart').click(function(){
        if($(this).children(".heart").children(".heart_img").attr("src") == "/img/heart-n.png"){
            var id = $(this).children(".heart").children(".heart_img").attr('title');
            var self_id =  '{{ Auth::user()->id}}';
            $('.heart_img').each(function(){
                var id2 = $(this).attr('title');
                if(id==id2){
                    $(this).prop("src","/img/heart-y.png");
                    $(this).parent(".heart").prev(".heart_sum").text( parseInt( $(this).parent(".heart").prev(".heart_sum").text().trim() ) + 1 );
                }
            })
        };
        if(self_id==id){
            $('.heart_oneself').prop("src","/img/heart-y.png");
            $('.self_sum').text($(this).children(".heart_sum").text());
        }
        $.ajax({
            url: '/user/add_heart_num',
            type: 'POST',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
            },
            data: {pro_id:id,type:'total'},
            dataType: 'json',
            success: function (data) {
                if (data.success == true) {

                }
            }
        });
    })
    /*积分过万显示万*/
    function integral(){
        $('.number_rank').each(function(){
            var Num=parseInt($(this).html());
            if(Num>=10000){
                Num=Math.floor((Num/10000)*10)/10;
                $(this).html(Num+"万");
            }
        })
        var Num1=parseInt($(".number_integral").text());
        if(Num1>=10000){
            Num1=Math.floor((Num1/10000)*10)/10;
            $(".number_integral").text(Num1+"万");
        }
    }
    integral();

    /*积分换算成等级*/
    $(".rank_dt").each(function(){
        var arr=$(this).text().split("Lv");
        var level=history_score(arr[1]);
        $(this).text('Lv'+level);
    })
    var level1=history_score({{ Auth::user()->integral }})
    $('.self_dt').text('Lv'+level1);
    function history_score(score) {
        if( score >= 0 && score < 100000)
        {
            return 0;
        }else if (score >= 100000 && score < 200000)
        {
            return 1;
        }else if (score >= 200000 && score < 400000)
        {
            return 2;
        }else if (score >= 400000 && score < 800000)
        {
            return 3;
        }else if (score >= 800000 && score < 1600000)
        {
            return 4;
        }else if (score >= 1600000 && score < 3200000)
        {
            return 5;
        }else if (score >= 3200000 && score < 6400000)
        {
            return 6;
        }else if (score >= 6400000 && score < 12800000)
        {
            return 7;
        }else if (score >= 12800000 && score < 25600000)
        {
            return 8;
        }else if (score >= 25600000 )
        {
            return 9;
        }
        return "∞";
    }
</script>
</html>
